package com.ruoyi.web.controller.nongjt;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.nongjt.domain.MemberDetailInfo;
import com.ruoyi.nongjt.service.MemberDetailInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员详细信息Controller
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@RestController
@RequestMapping("/nongjt/memberDetailInfo")
public class MemberDetailInfoController extends BaseController
{
    @Autowired
    private MemberDetailInfoService memberDetailInfoService;

    /**
     * 查询会员详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:memberDetailInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberDetailInfo memberDetailInfo)
    {
        startPage();
        List<MemberDetailInfo> list = memberDetailInfoService.selectMemberDetailInfoList(memberDetailInfo);
        return getDataTable(list);
    }

    /**
     * 导出会员详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:memberDetailInfo:export')")
    @Log(title = "会员详细信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberDetailInfo memberDetailInfo)
    {
        List<MemberDetailInfo> list = memberDetailInfoService.selectMemberDetailInfoList(memberDetailInfo);
        ExcelUtil<MemberDetailInfo> util = new ExcelUtil<MemberDetailInfo>(MemberDetailInfo.class);
        util.exportExcel(response, list, "会员详细信息数据");
    }

    /**
     * 获取会员详细信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:memberDetailInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(memberDetailInfoService.selectMemberDetailInfoById(id));
    }

    /**
     * 新增会员详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:memberDetailInfo:add')")
    @Log(title = "会员详细信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberDetailInfo memberDetailInfo)
    {
        return toAjax(memberDetailInfoService.insertMemberDetailInfo(memberDetailInfo));
    }

    /**
     * 修改会员详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:memberDetailInfo:edit')")
    @Log(title = "会员详细信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberDetailInfo memberDetailInfo)
    {
        return toAjax(memberDetailInfoService.updateMemberDetailInfo(memberDetailInfo));
    }

    /**
     * 删除会员详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:memberDetailInfo:remove')")
    @Log(title = "会员详细信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(memberDetailInfoService.logicDeleteMemberDetailInfoByIds(ids));
    }

    /**
     * 审核会员信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:memberDetailInfo:audit')")
    @Log(title = "审核会员信息", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody MemberDetailInfo memberDetailInfo)
    {
        return toAjax(memberDetailInfoService.auditMemberDetailInfo(memberDetailInfo));
    }

    /**
     * 重置密码
     */
    @PreAuthorize("@ss.hasPermi('nongjt:memberDetailInfo:resetPassword')")
    @Log(title = "重置密码", businessType = BusinessType.UPDATE)
    @PutMapping("/resetPassword")
    public AjaxResult resetPassword(@RequestBody MemberDetailInfo memberDetailInfo)
    {
        return toAjax(memberDetailInfoService.resetPassword(memberDetailInfo.getUserId(), memberDetailInfo.getRemark()));
    }
}
